﻿using AutoMapper;

using Holla.Infrastructure.EventBus;
using Holla.Infrastructure.EventBus.Abstractions;

using Microsoft.EntityFrameworkCore;

using Moq;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Holla.Infrastructure.TestBase
{
    public class TestClassBase<TAutoMapperProfile, TDbContext> where TAutoMapperProfile : Profile where TDbContext : DbContext
    {
        private TDbContext _dbContext;
        private Mock<IEventBus> _eventBusMock;
        private IMapper _mapper;

        protected TDbContext DbContext
        {
            get
            {
                return _dbContext ??= InMemoryDbContextFactory.Create<TDbContext>();
            }
        }

        protected IEventBus EventBus
        {
            get
            {
                if (_eventBusMock == null)
                {
                    _eventBusMock = new Mock<IEventBus>();
                    _eventBusMock.Setup(p => p.Publish(It.IsAny<IntegrationEvent>()));
                }

                return _eventBusMock.Object;
            }
        }

        protected IMapper Mapper
        {
            get
            {
                return _mapper ??= AutoMapperFactory.Create<TAutoMapperProfile>();
            }
        }
    }
}
